package spider;

/**
 * 已结被支持的网站小枚举
 */
public enum NovelSiteEnum {
    DingDianXiaoShuo(1,"23wx.cc"),
    BiQuGe(2,"biquzi.com"),
    BiXiaWenXue(3,"bxwx9.org"),
    KanShuZhong(4,"kanshuzhong.com");
    private int id;
    private String url;

    //region set get constructor
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    NovelSiteEnum(int id, String url) {
        this.id = id;
        this.url = url;
    }
    //endregion

    public static NovelSiteEnum getNovelSiteEnumById( int id){
        switch (id) {
            case 1:
                return DingDianXiaoShuo;
            case 2:
                return BiQuGe;
            case 3:
                return BiXiaWenXue;
            default:
                throw new RuntimeException("id=" + id + "是不被支持的小说网站");
        }
    }

    public static NovelSiteEnum getNovelSiteEnumByUrl( String url){
        for( NovelSiteEnum novelSiteEnum : values()){
            if(url.contains(novelSiteEnum.url)){
                return novelSiteEnum;
            }
        }
        throw new RuntimeException("url=" + url + "是不被支持的小说网站");
    }
}
